package com.zzsy.shoppingpro.utils;

import android.content.Context;
import android.os.Handler;

/**
 * Created by: zanjr
 * date: 2016/6/16
 * time: 13:45
 * description:
 */
public class Toast {

    private Toast() {
    }

    private static android.widget.Toast mToast;

    private static Handler mHandler = new Handler();

    private static Runnable r = new Runnable() {
        public void run() {
            mToast.cancel();
        }
    };

    private static void showToast(Context mContext, String text, int duration) {

        if (mContext == null) return;

        mHandler.removeCallbacks(r);

        if (mToast != null)
            mToast.setText(text);
        else {
            mToast = android.widget.Toast.makeText(mContext, text, android.widget.Toast.LENGTH_SHORT);
        }

        mHandler.postDelayed(r, duration);

        mToast.show();
    }

    public static void show(Context context, String message) {
        showToast(context, message, 2000);
    }

}
